package dp;

import java.util.Arrays;
import java.util.Scanner;

public class 小明的背包2 {

    static int N;
    static int V;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        N = scanner.nextInt();
        V = scanner.nextInt();
        //体积 价值
        int[][] shop = new int[N + 1][2];
        for (int i = 1; i <= N; i++) {
            shop[i][0] = scanner.nextInt();
            shop[i][1] = scanner.nextInt();
        }
        int[][] dp = new int[N + 1][V + 1];
        for (int i = 1; i <= N; i++) {
            int i_v = shop[i][0];
            int i_jia = shop[i][1];
            for (int j = 1; j <= V; j++) {
                if (j >= i_v) {
                    dp[i][j] = Integer.max(dp[i - 1][j], dp[i][j - i_v] + i_jia);
                } else {
                    dp[i][j] = dp[i - 1][j];
                }
            }
        }
        System.out.println(dp[N][V]);
    }

    private static void print(int[][] map) {
        System.out.println("====");
        for (int[] line : map) {
            System.out.println(Arrays.toString(line));
        }
        System.out.println("====");
    }
}
